home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / gcc / ixemlsrc.lha / ixemul / string / bcmp.c next >
C/C++ Source or Header  |  1996-03-13  |  3KB  |  74 lines

  1. /*-
  2.  * Copyright (c) 1990 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * This code is derived from software contributed to Berkeley by
  6.  * the Systems Programming Group of the University of Utah Computer
  7.  * Science Department.
  8.  *
  9.  * Redistribution and use in source and binary forms are permitted
  10.  * provided that: (1) source distributions retain this entire copyright
  11.  * notice and comment, and (2) distributions including binaries display
  12.  * the following acknowledgement:  ``This product includes software
  13.  * developed by the University of California, Berkeley and its contributors''
  14.  * in the documentation or other materials provided with the distribution
  15.  * and in all advertising materials mentioning features or use of this
  16.  * software. Neither the name of the University nor the names of its
  17.  * contributors may be used to endorse or promote products derived
  18.  * from this software without specific prior written permission.
  19.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  20.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  21.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  22.  */
  23.  
  24. /* bcmp(s1, s2, n) */
  25.  
  26. #include "defs.h"
  27.  
  28. /*
  29.  * This is probably not the best we can do, but it is still 2-10 times
  30.  * faster than the C version in the portable gen directory.
  31.  *
  32.  * Things that might help:
  33.  *    - longword align when possible (only on the 68020)
  34.  *    - use nested DBcc instructions or use one and limit size to 64K
  35.  */
  36. ENTRY(bcmp)
  37. asm("
  38.     movl    sp@(4),a0    /* string 1 */
  39.     movl    sp@(8),a1    /* string 2 */
  40.     movl    sp@(12),d0    /* length */
  41.     jeq    bcdone_bcmp    /* if zero, nothing to do */
  42.     movl    a0,d1
  43.     btst    #0,d1        /* string 1 address odd? */
  44.     jeq    bceven        /* no, skip alignment */
  45.     cmpmb    a0@+,a1@+    /* yes, compare a byte */
  46.     jne    bcnoteq        /* not equal, return non-zero */
  47.     subql    #1,d0        /* adjust count */
  48.     jeq    bcdone_bcmp    /* count 0, return zero */
  49. bceven:
  50.     movl    a1,d1
  51.     btst    #0,d1        /* string 2 address odd? */
  52.     jne    bcbloop        /* yes, no hope for alignment, compare bytes */
  53.     movl    d0,d1        /* no, both even */
  54.     lsrl    #2,d1        /* convert count to longword count */
  55.     jeq    bcbloop        /* count 0, skip longword loop */
  56. bclloop:
  57.     cmpml    a0@+,a1@+    /* compare a longword */
  58.     jne    bcnoteq        /* not equal, return non-zero */
  59.     subql    #1,d1        /* adjust count */
  60.     jne    bclloop        /* still more, keep comparing */
  61.     andl    #3,d0        /* what remains */
  62.     jeq    bcdone_bcmp    /* nothing, all done */
  63. bcbloop:
  64.     cmpmb    a0@+,a1@+    /* compare a byte */
  65.     jne    bcnoteq        /* not equal, return non-zero */
  66.     subql    #1,d0        /* adjust count */
  67.     jne    bcbloop        /* still more, keep going */
  68.     rts
  69. bcnoteq:
  70.     moveq    #1,d0
  71. bcdone_bcmp:
  72.     rts
  73. ");
  74.